package com.yuand.controller;


import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import com.yuand.entity.SysDictType;
import com.yuand.entity.SysUser;
import com.yuand.service.SysDictTypeService;
import com.yuand.utils.ResponseResult;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * <p>
 * 字典类型表 前端控制器
 * </p>
 *
 * @author yuandong
 * @since 2022-02-11
 */
@RestController
@RequestMapping("/sys/dict/type")
public class SysDictTypeController {

    @Autowired
    private SysDictTypeService sysDictTypeService;

    /**
     * 查询字典列表
     * @param dictType
     * @return
     */
    @GetMapping("/list")
    public ResponseResult list(@RequestParam(defaultValue = "1") Integer pageNum, @RequestParam(defaultValue = "10") Integer pageSize, SysDictType dictType) {
        PageHelper.startPage(pageNum, pageSize);
        List<SysDictType> list = this.sysDictTypeService.selectDictTypeList(dictType);
        PageInfo<SysDictType> pageInfo = new PageInfo<>(list);
        return new ResponseResult(0, "操作成功", pageInfo);
    }


    /**
     * 根据字典type的id进行查询
     * @param dictId
     * @return
     */
    @GetMapping("/{dictId}")
    public ResponseResult getDictType(@PathVariable Long dictId){
        SysDictType sysDictType = this.sysDictTypeService.selectDictTypeById(dictId);
        return new ResponseResult(0, "操作成功", sysDictType);
    }

}
